package com.stock.face.impl;

import com.stock.face.StockCacheFace;
import com.stock.mapper.StockBusinessMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component
public class StockCacheFaceImpl implements StockCacheFace {
    @Autowired
    private StockBusinessMapper stockBusinessMapper;

    @Cacheable(cacheNames = "stock", key = "'stockCodes'")
    @Override
    public List<String> getAllStockCodeWithPredix() {
        //1.获取所有A股股票的编码
        List<String> allStockCode = stockBusinessMapper.getAllStockCode();
        //2.添加股票前缀 sh sz
        allStockCode = allStockCode.stream()
                .map(code -> code.startsWith("6") ? "sh" + code : "sz" + code)
                .collect(Collectors.toList());
        return allStockCode;
    }
}
